﻿using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Controls;
using System.Windows.Media.Animation;


namespace MissedMemo.MeatAndCheeseDisc.OrderEntry
{
    public partial class viewOrderEditPanel : UserControl
    {
        public viewOrderEditPanel()
        {
            InitializeComponent();
        }


        internal void Open( Double containerHeight )
        {
            // Reset active tab and all 'dirty' flags, each time view is opened
            tabControl.SelectedIndex = 0;
            
            DoubleAnimation b = new DoubleAnimation( containerHeight, TimeSpan.Parse( "0:0:0.25" ) );

            b.FillBehavior = FillBehavior.Stop;  // Required, to enable height set to NaN

            // Setting height to NaN enables automatic adjustment to dynamic resizing of containing window
            b.Completed += delegate( object s, EventArgs args ) { Height = Double.NaN; };

            BeginAnimation( UserControl.HeightProperty, b );
        }


        private void Close()
        {
            DoubleAnimation b = new DoubleAnimation( ActualHeight, 0, TimeSpan.Parse( "0:0:0.25" ) );

            BeginAnimation( UserControl.HeightProperty, b );
        }


        private void OnDone( object sender, RoutedEventArgs e )
        {
            Close();
        }
    }
}
